/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2015年3月18日         luwei
 */

package com.coocaa.app.gamecenter.pages.search;

import android.content.Context;
import android.view.KeyEvent;
import android.view.View;
import android.widget.FrameLayout;

import com.coocaa.app.gamecenter.framework.ui.GameCenterBaseLayout;
import com.tianci.appstore.audio.IAudio;
import com.tianci.appstore.ui.data.SkyListAppData;
import com.tianci.appstore.ui.data.SkyListAppData.ListType;
import com.tianci.appstore.ui.search.SearchListView;
import com.tianci.appstore.ui.search.SearchListView.OnShowLoadingListener;
import com.tianci.appstore.ui.search.SearchMainLayout;

public class GameSearchLayout extends GameCenterBaseLayout {
    private SearchListView mSearchListView = null;
    private SearchMainLayout mInputLayout = null;

    public GameSearchLayout(Context context, OnShowLoadingListener listener) {
        super(context);
        addContentLayout(listener);
    }

    private void addContentLayout(OnShowLoadingListener listener) {
        mInputLayout = new SearchMainLayout(mContext, 1);
        mInputLayout.setFocusViewEvent(focusChangedEvent);
        mInputLayout.initUI();
        addView(mInputLayout);
        mSearchListView = new SearchListView(mContext, ListType.SEARCH_LIST) {

            @Override
            public void onBlockClicked(View v, SkyListAppData data, int index) {
                // TODO Auto-generated method stub

            }

            @Override
            public void destroyController() {

            }

            @Override
            public void resume() {
                // TODO Auto-generated method stub

            }

            @Override
            public IAudio getAudioInterface() {
                // TODO Auto-generated method stub
                return null;
            }
        };
        mSearchListView.setFocusChangeEvent(focusChangedEvent);
        mSearchListView.setShowLoadingListener(listener);
        mSearchListView.createView();
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Div(1006),
                LayoutParams.MATCH_PARENT);
        params.leftMargin = Div(803);
        addView(mSearchListView, params);
        mInputLayout.setSearchKeyChangeListener(mSearchListView.getController());
        mInputLayout.setClearFocusListener(mSearchListView.getController());
        mSearchListView.getController().setSearchResultListener(mInputLayout);
        mSearchListView.getController().setStatusBar(mStatusBar);
    }

    public void setShowLoadingListener(OnShowLoadingListener listener) {
        mSearchListView.setShowLoadingListener(listener);
    }


    public boolean keyDown(int keyCode, KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            String key = "";
            switch (keyCode) {
                case KeyEvent.KEYCODE_0:
                    key = "0";
                    break;
                case KeyEvent.KEYCODE_1:
                    key = "1";
                    break;
                case KeyEvent.KEYCODE_2:
                    key = "2";
                    break;
                case KeyEvent.KEYCODE_3:
                    key = "3";
                    break;
                case KeyEvent.KEYCODE_4:
                    key = "4";
                    break;
                case KeyEvent.KEYCODE_5:
                    key = "5";
                    break;
                case KeyEvent.KEYCODE_6:
                    key = "6";
                    break;
                case KeyEvent.KEYCODE_7:
                    key = "7";
                    break;
                case KeyEvent.KEYCODE_8:
                    key = "8";
                    break;
                case KeyEvent.KEYCODE_9:
                    key = "9";
                    break;
                case 0:
                case KeyEvent.KEYCODE_DEL:
                    if (mInputLayout != null) {
                        mInputLayout.deleteValue();
                    }
                    return true;
                default:
                    break;
            }
            if (!key.equals("")) {
                mInputLayout.addValue(key);
            }
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void destory() {
        super.destory();
    }

    @Override
    public View getContentView() {
        // TODO Auto-generated method stub
        return null;
    }


}
